package com.study.demo_aop.component;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @ClassName: LogComponent
 * @Description:
 * @author: WS
 * @date 2020/12/13
 * @Version: 1.0
 **/
@Component
@Aspect
public class LogComponent {
    @Pointcut("execution(* com.study.demo_aop.service.*.*(..))")
    public void pc1(){
    }
    @Before("pc1()")
    public void before(JoinPoint jp){
        String name = jp.getSignature().getName();
        System.out.println("before>>>>>"+name);
    }
    @After("pc1()")
    public void after(JoinPoint jp){
        String name = jp.getSignature().getName();
        System.out.println("after>>>>>"+name);
    }
    @AfterReturning(value = "pc1()",returning = "object")
    public Object afterreturning(JoinPoint jp,Object object){
        String name = jp.getSignature().getName();
        System.out.println("afterreturning>>>>>"+name+",object:"+object);
        return object;
    }
    @AfterThrowing(value = "pc1()",throwing = "object")
    public void afterthrowing(JoinPoint jp,Exception object){
        String name = jp.getSignature().getName();
        System.out.println("afterthrowing>>>>>"+name+",exception:"+object);
    }
    @Around("pc1()")
    public Object around(ProceedingJoinPoint jp) throws Throwable {
        String name = jp.getSignature().getName();
        Object proceed = jp.proceed();
        System.out.println("around>>>>>"+name+",proceed:"+proceed);
        return proceed;
    }
}
